const Zan = require('../../../dist/index');
const config = require('./config');

Page(Object.assign({}, Zan.Field, {
  /**
   * 页面的初始数据
   */
  data: {
    config,
    navLeftItems: [],
    navRightItems: [],
    curNav: 2,
    curIndex: 0,
    screenHeight:0
  },
  onLoad: function () {
    this.setData({
      screenHeight: wx.getSystemInfoSync().windowHeight
    }) 
    // 加载的使用进行网络访问，把需要的数据设置到data数据对象
    var res = [{
      "id": 2, "tree": {
        "id": 2, "desc": "主机及配件", "desc2": null, "level": "level1", "logo": null, "popular": null, "nodes": [
          {
            "id": 4, "tree": {
              "id": 4, "desc": "纸尿裤", "desc2": null, "level": "level2", "logo": "", "popular": null, "nodes": [
                { "id": 16, "tree": { "id": 16, "desc": "花王", "desc2": "Merries", "level": "level3", "logo": "", "popular": 16, "nodes": null } }, { "id": 17, "tree": { "id": 17, "desc": "大王", "desc2": "Goon", "level": "level3", "logo": "", "popular": 17, "nodes": null } }, { "id": 18, "tree": { "id": 18, "desc": "尤妮佳", "desc2": "Moony", "level": "level3", "logo": "", "popular": 18, "nodes": null } }]
            }, "logo": ""
          },
          {
            "id": 4, "tree": {
              "id": 4, "desc": "纸尿裤", "desc2": null, "level": "level2", "logo": "", "popular": null, "nodes": [
                { "id": 16, "tree": { "id": 16, "desc": "花王", "desc2": "Merries", "level": "level3", "logo": "", "popular": 16, "nodes": null } }, { "id": 17, "tree": { "id": 17, "desc": "大王", "desc2": "Goon", "level": "level3", "logo": "", "popular": 17, "nodes": null } }, { "id": 18, "tree": { "id": 18, "desc": "尤妮佳", "desc2": "Moony", "level": "level3", "logo": "", "popular": 18, "nodes": null } }]
            }, "logo": ""
          },
          { "id": 88, "tree": { "id": 29, "desc": "湿巾", "desc2": null, "level": "level2", "logo": "", "popular": 29, "nodes": [{ "id": 49, "tree": { "id": 49, "desc": "贝亲", "desc2": "Pigeon", "level": null, "logo": "", "popular": null, "nodes": null } }, { "id": 16, "tree": { "id": 16, "desc": "花王", "desc2": "Merries", "level": "level3", "logo": "", "popular": 16, "nodes": null } }] }, "logo": "" },
          { "id": 89, "tree": { "id": 279, "desc": "湿巾", "desc2": null, "level": "level2", "logo": "", "popular": 89, "nodes": [{ "id": 49, "tree": { "id": 49, "desc": "贝亲", "desc2": "Pigeon", "level": null, "logo": "", "popular": null, "nodes": null } }, { "id": 16, "tree": { "id": 16, "desc": "花王", "desc2": "Merries", "level": "level3", "logo": "", "popular": 16, "nodes": null } }] }, "logo": "" }]
      }
    }, { "id": 1, "tree": { "id": 1, "desc": "连接材料", "desc2": null, "level": "level1", "logo": null, "popular": null, "nodes": [] } },
    { "id": 101, "tree": { "id": 106, "desc": "控制系统", "desc2": null, "level": "level1", "logo": null, "popular": null, "nodes": [] } },
    { "id": 102, "tree": { "id": 108, "desc": "地面采暖", "desc2": null, "level": "level1", "logo": null, "popular": null, "nodes": [] } },
    { "id": 103, "tree": { "id": 109, "desc": "卫生间电地暖", "desc2": null, "level": "level1", "logo": null, "popular": null, "nodes": [] } }];
    this.setData({
      navLeftItems: res,
      navRightItems: res
    })
  },

  //事件处理函数
  switchRightTab: function (e) {
    // 获取item项的id，和数组的下标值
    let id = e.target.dataset.id,
      index = parseInt(e.target.dataset.index);
    // 把点击到的某一项，设为当前index
    this.setData({
      curNav: id,
      curIndex: index
    })
  }

}))